const express = require("express");
const path = require("path");
const ejs = require("ejs");
const cors = require("cors");
const { port } = require("./config");

const noteRouter = require("./router/note");
const userRouter = require("./router/user");
const app = express();

app.use(express.static("./public"));

// 处理跨域
app.use(
  cors({
    origin: "*",
    methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
  })
);

// 获取静态路径
app.use(express.static(__dirname + "/dist"));
app.use(express.static(__dirname + "/data"));

// 解析数据
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// 使用路由
app.use("/wall", noteRouter);
app.use("/api", userRouter);

app.listen(port, () => {
  console.log(`启动端口 ${port} 成功`);
});
